-- 上机练习一 事务提交
BEGIN;
INSERT INTO t_student(id,student_name,age,gender,birthday,classID,begin_year)
VALUES(1001,'张三',20,'女','2003-09-18',3,2023)
UPDATE t_student SET student_name='张三',age=20 WHERE studentID=1001;
DELETE FROM t_student WHERE age<18;
COMMIT;
-- 上机练习二 事务提交
CREATE TABLE account(
id,INT AUTO_INCREMENT PRIMARY KEY,
account_name VARCHAR(20) NOT NULL,
phone VARCHAR(11) NOT NULL,
balance DECIMAL(30,5));
INSERT INTO account VALUES('6225214702630552','张三','13541522563',100);
INSERT INTO account VALUES('6225214702630562','李四','13012123443',100);
START TRANSACTION;
UPDATE account SET balance=balance_200 WHERE id='6225214702630552';
UPDATE account SET balance=balance_200 WHERE id='6225214702630562';
-- 上机练习三 创建索引
CREATE TABLE student(
id,INT AUTO_INCREMENT PRIMARY KEY,
student_name VARCHAR(20) NOT NULL,-- 姓名
phone VARCHAR(11) NOT NULL,
gender ENUM('男','女'));
BEGIN;
DECLARE i INT DEFAULT(1);
WHERE i<=100000 DO
INSERT INTO student(id,student_name)
VALUES(i,concat('张三',i),'13193010765','张三'）；
SET i = i+1;
EXPLAIN SELECT * FROM student where  student_name='张三';
CREATE UNIQUE INDEX student_name_index ON student(student_name);
EXPLAIN SELECT * FROM student where  student_name='张三';
 -- 上机练习四 创建视图
CREATE VIEW view_student_san
AS SELECT studentID,student_name
FROM t_student
WHERE student_name='张耀仁';